<HTML><HEAD> <!-- ----------- Stop Button ----------- --> <SCRIPT LANGUAGE="JavaScript"><!-- hide from old browsers /* THE JAVASCRIPT COOKBOOK by Erica Sadun, webrx@mindspring.com Copyright (c)2000 by Charles River Media. All Rights Reserved. This applet can only be re-used or modifed by license holders of the JavaScript Cookbook CD-ROM. Credit must be given in the source code and this copyright notice must be maintained. If you do not hold a license to the JavaScript Cookbook, you may NOT duplicate or modify this code for your own use. Use at your own risk. No warranty is given or implied of the suitability of this applet for any specific application. Neither Erica Sadun nor Charles River Media will be held responsible for any unwanted effects due to the use of this applet or any derivative. */ var str="" var direction="left" function setMessage() { msg = "YOUR MESSAGE HERE" /* initialize the string to a bit from the left */ if (str == "") str = " "+msg if (str.length < 20) { // leftmost: swing to the right direction = "right" str = " " + str } else if (str.length > 110) { // rightmost: swing to the left direction = "left" str = str.substring(3, str.length) } else if (direction == "left") { // nudge left -- make shorter str = str.substring(2, str.length) } else { // nudge right -- make longer str = " "+str } window.status = str JSCTimeOutID = window.setTimeout('setMessage()',100) } <!-- done hiding --></SCRIPT></HEAD> <BODY bgcolor="ffffff" link="0000ff" vlink="770077" onload="JSCTimeOutID = window.setTimeout('setMessage()',500);"> <FONT COLOR="007777"><H1><IMG SRC="../GRAFX/UTENS.JPG" WIDTH=80 HEIGHT=50 ALIGN = LEFT>Marquee #6: The Stop Button</H1></FONT> <BLOCKQUOTE><FONT COLOR="770000"> This script repeats the functionality of Marquee #2, with an added "stop" button. </FONT></BLOCKQUOTE> <BR><BR> <CENTER><FORM> <INPUT TYPE="BUTTON" VALUE=" S T O P " onClick="clearTimeout(JSCTimeOutID)"><p> <INPUT TYPE="BUTTON" VALUE="Call setMessage() to Restart" onClick="setMessage()"><p> <!-- Recall that history.go(0) reloads a page --> <INPUT TYPE="BUTTON" VALUE="Reload to Restart" onClick="history.go(0)"> </FORM></CENTER> <BR><BR> <FONT COLOR="007777"><H2>Discussion</H2></FONT> <FONT SIZE=4> Halt timeout-loops by calling <FONT COLOR="770000">clearTimeout</FONT> on the current timeout process. In this example the onClick event handler, <FONT COLOR="770000">onClick="clearTimeout(JSCTimeOutID)"</FONT> clears the pending event and prevents the <FONT COLOR="770000">setMessage()</FONT> event from executing--and hence from starting a new timeout. </FONT> <h5>Copyright ©1996 by Charles River Media, All Rights Reserved</h5> </BODY> </HTML>